// create a 2D array; catch exception thrown by new when
// sufficient memory is not available
// return true iff successful in creating the 2d array

#ifndef make2dArray_
#define make2dArray_

#include<iostream>

using namespace std;

template <class T>
//template <typename T>
bool make2dArray(T** &x, int numberOfRows, int numberOfColumns)
{// create a two dimensional array.
    try
    {
        // create pointers for the rows
        x = new T* [numberOfRows];

        // get memory for each row
        for(int i = 0; i < numberOfRows; i++)
        {
            x[i] = new T [numberOfColumns];
        }
        return true;
    }
    catch(bad_alloc e)
    {
        return false;
    }
    
} 

#endif
